<template>
  <div class="goods" style="min-height:100vh;">
    <div class="topBar">
      <van-icon class="i_left" name="arrow-left" @click="$router.back()" />
      <span>注册</span>
    </div>  
    <div class="formOuter">
      <div class="formTit"><span>矿泉之源</span></div>
    <div class="formBox">
      <div class="formCol">
        <i class="colIcon i_phone"></i>
        <input
          class="inputInner"
          type="number"
          v-model="info.phone"
          placeholder="请输入手机号码"
        />
      </div>
      <div class="hasCode">
        <div class="formCol">
          <i class="colIcon i_code"></i>
          <input
            class="inputInner"
            type="number"
            v-model="info.code"
            placeholder="请输入验证码"
          />
        </div>
        <Code :phone="info.phone" type="register"></Code>
      </div>
      <div class="formCol">
        <i class="colIcon i_psw"></i>
       <input
          class="inputInner"
          type="password"
          v-model="info.password"
          placeholder="请输入密码"
        />
      </div>
      <div class="formCol">
        <i class="colIcon i_money"></i>
       <input
          class="inputInner"
          type="text"
          v-model="info.member_code"
          placeholder="请输入财富码"
        />
      </div>
      <a href="javascript:;" class="confirmBtn" @click="save">立即注册</a>
      <div class="haSAccount">
        <a
          href="javascript:;"
          @click="goLogin"
        >立即登录</a>
      </div>
    </div>
    </div>
  </div>
</template>

<script>
import Code from '../../components/Code';
export default {
  components: {
    Code
  },
  data () {
    return {
      pathUrl: '',
      value: '+86',
      columns: ['+86', '+852', '+853', '+886'],
      showPicker: false,
      info: { phone: '' }
    };
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {    
      vm.pathUrl = from.fullPath
    })
  },
  created() {
    if (this.$route.query.member_code) {
      this.info.member_code = this.$route.query.member_code
    }
  },
  methods: {
    onConfirm (value) {
      this.value = value;
      this.showPicker = false;
    },
    save () {
      this.sendReq('member/register', this.info, r => {
        this.alert('注册成功')
        setTimeout(() => {
          if (this.pathUrl.indexOf('login') > -1) {
            this.$router.back()
          } else {
            this.$router.push({path: '/login'})
          }
        }, 1000)
      })
    },
    goLogin() {
      if (this.pathUrl.indexOf('login') > -1) {
        this.$router.back()
      } else {
        this.$router.push({path: '/login'})
      }
    },
  }
};
</script>

<style lang="less" scoped>
.goods {
  padding: 50px 15px 50px 15px;
  background: url(../../assets/bg.png) no-repeat center center;
  background-size: 100% 100%;  
}
.formOuter{
  width:350px;
  background:#fff;
  margin:0 auto;
  box-shadow: 0px 4px 3px 1px rgba(51, 174, 244, 0.25);
  border-radius: 16px;
  padding:45px 0;
    .formTit {
      font-size: 25px;
      font-weight: 600;
      color: #000000;
      line-height: 26px;
      text-align: center;
    }
}
.formInfo {
  font-size: 12px;
  font-weight: 500;
  color: #999999;
}

.formBox {
  margin: 0 auto;
  padding: 10px 0;
  width: 300px;
  .formCol {
    width: 100%;
    height: 40px;
    border-bottom:1px solid #EBEBEB;
    margin: 15px 0;
    position: relative;
    .inputInner {
      position: absolute;
      width: 100%;
      height: 100%;
      background: transparent;
      top: 0;
      left: 0;
      border: none;
      outline: none;
      font-size: 14px;
      padding: 0 40px;
      box-sizing: border-box;
    }
    .inputInner::placeholder {
      color: #999;
    }
    .colIcon,
    .colline,
    .i_eyes {
      display: block;
      position: absolute;
    }
    .colIcon {
      width: 14px;
      height: 15px;
      top: 50%;
      margin-top: -8px;
      left: 15px;
    }
    .i_user {
      background: url(../../assets/i_user.png) no-repeat center center;
      background-size: 100% 100%;
    }
    .i_card {
      background: url(../../assets/i_card.png) no-repeat center center;
      background-size: 100% 100%;
    }
    .i_code {
      background: url(../../assets/i_code.png) no-repeat center center;
      background-size: 100% 100%;
    }
    .i_phone {
      background: url(../../assets/i_phone.png) no-repeat center center;
      background-size: 100% 100%;
    }
    .i_psw {
      background: url(../../assets/i_psw.png) no-repeat center center;
      background-size: 100% 100%;
    }
    .i_money {
      background: url(../../assets/i_money.png) no-repeat center center;
      background-size: 100% 100%;
    }
  }
  .hasCode{position: relative;}
  .forgetPsw {
    display: block;
    width: 100%;
    text-decoration: none;
    text-align: right;
    font-size: 15px;
    font-weight: 500;
    color: #ff3c3c;
  }
  .haSAccount {
    width: 100%;
    text-align: center;
    font-size: 15px;
    font-weight: 500;
    color: #28282c;
    margin-top: 15px;
    a {
      color: #389EFF;
      text-decoration: none;
    }
  }
  .confirmBtn {
    display: block;
    width: 100%;
    height: 40px;
    background: #389EFF;
    border-radius: 20px;
    text-align: center;
    line-height: 40px;
    font-size: 15px;
    font-weight: 500;
    color: #fff;
    margin-top: 30px;
  }
  .q_link {
    display: flex;
    justify-content: space-between;
    padding: 15px 0;
    a {
      font-size: 15px;
      font-weight: 500;
      color: #389EFF;
    }
  }
}
</style>
